package com.k2data.etl;

import java.util.HashMap;

public class RequestConfUtil {

    public static RequestConf getLoginRequest() {
        RequestConf rc = new RequestConf();
        rc.setUrl("https://10.10.3.113/rs/esm/v2/login");

        rc.setHeaders(new HashMap<>());
        rc.getHeaders().put("Content-Type", "application/json");

        rc.setMethod("POST");

        rc.setBody(new HashMap<>());
        rc.getBody().put("username", "emhpZHU=");
        rc.getBody().put("password", "WmQxMjM0NTY3OCE=");
        rc.getBody().put("locale", "en_US");

        return rc;
    }

    //{"query":{"fields":{"opt":"SELECT","opr":["Alert.IPSIDAlertID","Alert.Severity","Rule.msg","Alert.EventCount","Alert.SrcIP","Alert.DstIP","Alert.Protocol","Alert.LastTime","Action.Name","Alert.AvgSeverity"],"exp":[]},"sources":{"opt":"SOURCE","opr":[],"exp":[{"opt":"EQUALS","opr":["QUERYID","6"],"exp":[]},{"opt":"EQUALS","opr":["ESMQUERYTYPE","EVENT"],"exp":[]},{"opt":"EQUALS","opr":["ESMQUERYDEVICESOURCE","Alert.IPSID"],"exp":[]}]},"filters":{"opt":"AND","opr":null,"exp":[{"opt":"EQUALS","opr":["Alert.LastTime","$Previous,?Day,DV,DV"],"exp":null},{"opt":"EQUALS","opr":["Alert.IPSID","144115188075855872/8"],"exp":null}]},"groups":{},"orders":{"opt":"ORDER","opr":[],"exp":[{"opt":"DESC","opr":["8"],"exp":[]},{"exp":null,"opr":["1"],"opt":"DESC"}]}},"customOptions":{"requireTimeFrame":false},"queryParameters":[],"limit":100,"offset":0,"reverse":false,"getTotal":true}

    public static RequestConf getR1() {
        RequestConf rc = new RequestConf();

        rc.setUrl("https://10.10.3.113/rs/v1/runningQuery");

        rc.setHeaders(new HashMap<>());
        rc.getHeaders().put("Content-Type", "application/json");
        rc.setMethod("POST");

        rc.setBodyStr("{\"query\":{\"fields\":{},\"sources\":{\"opt\":\"SOURCE\",\"opr\":[],\"exp\":[{\"opt\":\"EQUALS\",\"opr\":[\"QUERYID\",\"32\"],\"exp\":[]},{\"opt\":\"EQUALS\",\"opr\":[\"ESMQUERYTYPE\",\"EVENT\"],\"exp\":[]},{\"opt\":\"EQUALS\",\"opr\":[\"ESMQUERYDEVICESOURCE\",\"Alert.IPSID\"],\"exp\":[]}]},\"filters\":{\"opt\":\"AND\",\"opr\":null,\"exp\":[{\"opt\":\"EQUALS\",\"opr\":[\"Alert.LastTime\",\"$Current,?Day,DV,DV\"],\"exp\":null},{\"opt\":\"EQUALS\",\"opr\":[\"Alert.IPSID\",\"144115188075855872/8\"],\"exp\":null}]},\"groups\":{},\"orders\":{\"opt\":\"ORDER\",\"opr\":null,\"exp\":[{\"opt\":\"DESC\",\"opr\":[\"3\"],\"exp\":null}]}},\"customOptions\":{\"requireTimeFrame\":false},\"queryParameters\":[],\"limit\":20000,\"offset\":0,\"reverse\":false,\"getTotal\":true}");

        return rc;
    }

    public static RequestConf getR2() {
        RequestConf rc = new RequestConf();

        rc.setUrl("https://10.10.3.113/rs/v1/runningQuery");

        rc.setHeaders(new HashMap<>());
        rc.getHeaders().put("Content-Type", "application/json");
        rc.setMethod("POST");

        rc.setBodyStr("{\"query\":{\"fields\":{\"opt\":\"SELECT\",\"opr\":[\"Alert.IPSIDAlertID\",\"Alert.Severity\",\"Rule.msg\",\"Alert.EventCount\",\"Alert.SrcIP\",\"Alert.DstIP\",\"Alert.Protocol\",\"Alert.LastTime\",\"Action.Name\",\"Alert.AvgSeverity\"],\"exp\":[]},\"sources\":{\"opt\":\"SOURCE\",\"opr\":[],\"exp\":[{\"opt\":\"EQUALS\",\"opr\":[\"QUERYID\",\"6\"],\"exp\":[]},{\"opt\":\"EQUALS\",\"opr\":[\"ESMQUERYTYPE\",\"EVENT\"],\"exp\":[]},{\"opt\":\"EQUALS\",\"opr\":[\"ESMQUERYDEVICESOURCE\",\"Alert.IPSID\"],\"exp\":[]}]},\"filters\":{\"opt\":\"AND\",\"opr\":null,\"exp\":[{\"opt\":\"EQUALS\",\"opr\":[\"Alert.LastTime\",\"$Previous,?Day,DV,DV\"],\"exp\":null},{\"opt\":\"EQUALS\",\"opr\":[\"Alert.IPSID\",\"144115188075855872/8\"],\"exp\":null}]},\"groups\":{},\"orders\":{\"opt\":\"ORDER\",\"opr\":[],\"exp\":[{\"opt\":\"DESC\",\"opr\":[\"8\"],\"exp\":[]},{\"exp\":null,\"opr\":[\"1\"],\"opt\":\"DESC\"}]}},\"customOptions\":{\"requireTimeFrame\":false},\"queryParameters\":[],\"limit\":10000,\"offset\":0,\"reverse\":false,\"getTotal\":true}");

        return rc;
    }

    /**
     * event stat
     * @return
     */
    public static RequestConf getR3(){
        RequestConf rc = new RequestConf();

        rc.setUrl("https://10.10.3.113/rs/v1/runningQuery");

        rc.setHeaders(new HashMap<>());
        rc.getHeaders().put("Content-Type", "application/json");
        rc.setMethod("POST");

        // level-1
        rc.setBodyStr("{\"query\":{\"fields\":{\"opt\":\"SELECT\",\"opr\":[\"Alert.IPSIDAlertID\",\"Alert.Severity\",\"Rule.msg\",\"Alert.EventCount\",\"Alert.SrcIP\",\"Alert.DstIP\",\"Alert.Protocol\",\"Alert.LastTime\",\"Action.Name\",\"Alert.AvgSeverity\"],\"exp\":[]},\"sources\":{\"opt\":\"SOURCE\",\"opr\":[],\"exp\":[{\"opt\":\"EQUALS\",\"opr\":[\"QUERYID\",\"6\"],\"exp\":[]},{\"opt\":\"EQUALS\",\"opr\":[\"ESMQUERYTYPE\",\"EVENT\"],\"exp\":[]},{\"opt\":\"EQUALS\",\"opr\":[\"ESMQUERYDEVICESOURCE\",\"Alert.IPSID\"],\"exp\":[]}]},\"filters\":{\"opt\":\"AND\",\"opr\":null,\"exp\":[{\"opt\":\"EQUALS\",\"opr\":[\"Alert.LastTime\",\"11/12/2018 22:00:00,DV,11/13/2018 00:00:00,DV\"],\"exp\":null},{\"opt\":\"EQUALS\",\"opr\":[\"Alert.IPSID\",\"144115188075855872/8\"],\"exp\":null}]},\"groups\":{},\"orders\":{\"opt\":\"ORDER\",\"opr\":[],\"exp\":[{\"opt\":\"DESC\",\"opr\":[\"8\"],\"exp\":[]},{\"exp\":null,\"opr\":[\"1\"],\"opt\":\"DESC\"}]}},\"customOptions\":{\"requireTimeFrame\":false},\"queryParameters\":[],\"limit\":100000000,\"offset\":0,\"reverse\":false,\"getTotal\":true}");
        // level-2
        rc.setBodyStr("{\"query\":{\"fields\":{},\"sources\":{\"opt\":\"SOURCE\",\"opr\":[],\"exp\":[{\"opt\":\"EQUALS\",\"opr\":[\"QUERYID\",\"113\"],\"exp\":[]},{\"opt\":\"EQUALS\",\"opr\":[\"ESMQUERYTYPE\",\"EVENT\"],\"exp\":[]},{\"opt\":\"EQUALS\",\"opr\":[\"ESMQUERYDEVICESOURCE\",\"Alert.IPSID\"],\"exp\":[]}]},\"filters\":{\"opt\":\"AND\",\"opr\":null,\"exp\":[{\"opt\":\"EQUALS\",\"opr\":[\"Alert.LastTime\",\"$Last,?Minute10,DV,DV\"],\"exp\":null},{\"opt\":\"EQUALS\",\"opr\":[\"Alert.IPSID\",\"144115188075855872/8\"],\"exp\":null}]},\"groups\":{},\"orders\":{\"opt\":\"ORDER\",\"opr\":null,\"exp\":[{\"opt\":\"DESC\",\"opr\":[\"4\"],\"exp\":null}]}},\"customOptions\":{\"requireTimeFrame\":false,\"netmask\":28},\"queryParameters\":[],\"limit\":10,\"offset\":0,\"reverse\":false,\"getTotal\":true}");

        return rc;
    }

    /**
     * log stat
     * @return
     */
    public static RequestConf getR4(){
        RequestConf rc = new RequestConf();

        rc.setUrl("https://10.10.3.113/rs/v1/runningQuery");

        rc.setHeaders(new HashMap<>());
        rc.getHeaders().put("Content-Type", "application/json");
        rc.setMethod("POST");

        rc.setBodyStr("{\"query\":{\"fields\":{},\"sources\":{\"opt\":\"SOURCE\",\"opr\":[],\"exp\":[{\"opt\":\"EQUALS\",\"opr\":[\"QUERYID\",\"113\"],\"exp\":[]},{\"opt\":\"EQUALS\",\"opr\":[\"ESMQUERYTYPE\",\"EVENT\"],\"exp\":[]},{\"opt\":\"EQUALS\",\"opr\":[\"ESMQUERYDEVICESOURCE\",\"Alert.IPSID\"],\"exp\":[]}]},\"filters\":{\"opt\":\"AND\",\"opr\":null,\"exp\":[{\"opt\":\"EQUALS\",\"opr\":[\"Alert.LastTime\",\"11/13/2018 00:00:00,DV,11/14/2018 23:59:59,DV\"],\"exp\":null},{\"opt\":\"EQUALS\",\"opr\":[\"Alert.IPSID\",\"144115188075855872/8\"],\"exp\":null}]},\"groups\":{},\"orders\":{\"opt\":\"ORDER\",\"opr\":null,\"exp\":[{\"opt\":\"DESC\",\"opr\":[\"4\"],\"exp\":null}]}},\"customOptions\":{\"requireTimeFrame\":false,\"netmask\":21},\"queryParameters\":[],\"limit\":10,\"offset\":0,\"reverse\":false,\"getTotal\":true}");

        return rc;
    }


    public static RequestConf getRequest(String location) {
        RequestConf rc = new RequestConf();

        rc.setUrl("https://10.10.3.113/rs" + location);

        rc.setHeaders(new HashMap<>());
        rc.getHeaders().put("Content-Type", "application/json");
        rc.setMethod("GET");

        return rc;
    }


    public static void main(String[] args){
        System.out.println(getR1().getBodyStr());
    }
}
